package gui;

import entities.User;

import java.awt.EventQueue;
import java.awt.Font;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.AbstractAction;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Action;

public class WindowBuilder {

	private JFrame frame;
	private JPanel pnlAccount;
	private JPasswordField pswPassword;
	private JPasswordField pswPasswordConfirm;
	private JTextField txtUsernameDisplay;
	private JTextField txtEmail;
	private JTextField txtEmailConfirm;
	private JLabel lblAccount;
	private JTextField txtFirstName;
	private JTextField txtLastName;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					WindowBuilder window = new WindowBuilder();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public WindowBuilder() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100,100,818,647);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		
		pnlAccount = new JPanel();
		pnlAccount.setBounds(0,0,800,600);
		pnlAccount.setLayout(null);
		
		lblAccount = new JLabel("username");
		lblAccount.setFont(new Font("Arial Rounded MT Bold", Font.PLAIN, 20));
		lblAccount.setBounds(50, 50, 250, 22);
		pnlAccount.add(lblAccount);
		
		JLabel lblUsername = new JLabel("Username");
		lblUsername.setBounds(50, 125, 75, 16);
		pnlAccount.add(lblUsername);
		
		JLabel lblEmail = new JLabel("Email");
		lblEmail.setBounds(50, 236, 75, 16);
		pnlAccount.add(lblEmail);
		
		JLabel lblEmailConfirm = new JLabel("Email Confirm");
		lblEmailConfirm.setBounds(50, 269, 90, 16);
		pnlAccount.add(lblEmailConfirm);
		
		JLabel lblPassword = new JLabel("Password");
		lblPassword.setBounds(50, 318, 75, 16);
		pnlAccount.add(lblPassword);
		
		JLabel lblPasswordConfirm = new JLabel("Password Confirm");
		lblPasswordConfirm.setBounds(50, 347, 120, 16);
		pnlAccount.add(lblPasswordConfirm);
		
		pswPassword = new JPasswordField();
		pswPassword.setBounds(180, 315, 325, 22);
		pnlAccount.add(pswPassword);
		
		pswPasswordConfirm = new JPasswordField();
		pswPasswordConfirm.setBounds(180, 344, 325, 22);
		pnlAccount.add(pswPasswordConfirm);
		
		txtUsernameDisplay = new JTextField("username");
		txtUsernameDisplay.setBounds(180, 122, 325, 22);
		pnlAccount.add(txtUsernameDisplay);
		
		txtEmail = new JTextField("email");
		txtEmail.setBounds(180, 236, 325, 22);
		pnlAccount.add(txtEmail);
		
		txtEmailConfirm = new JTextField();
		txtEmailConfirm.setBounds(180, 267, 325, 22);
		pnlAccount.add(txtEmailConfirm);
		
		JButton btnChangeUsername = new JButton("Change Username");
		btnChangeUsername.setBounds(530, 121, 150, 25);
		btnChangeUsername.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				String username = txtUsernameDisplay.getText();
//				windowsApp.getUser().setUsername(username);
				lblAccount.setText(username);
				System.out.println("USERNAME CHANGED");
			}
		});
		pnlAccount.add(btnChangeUsername);
		
		JButton btnChangeEmail = new JButton("Change Email");
		btnChangeEmail.setBounds(530, 265, 150, 25);
		btnChangeEmail.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				String email = txtEmail.getText();
				String emailConfirm = txtEmailConfirm.getText();
				
				if(email.equals(emailConfirm)){
//					windowsApp.getUser().setEmail(email);
				}
				
				System.out.println("EMAIL CHANGED");
			}
		});
		pnlAccount.add(btnChangeEmail);
		
		JButton btnChangePassword = new JButton("Change Password");
		btnChangePassword.setBounds(530, 343, 150, 25);
		btnChangePassword.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				String password = String.valueOf(pswPassword.getPassword());
				String passwordConfirm = String.valueOf(pswPasswordConfirm.getPassword());
				
				if(password.equals(passwordConfirm)){
//					windowsApp.getUser().setPassword(password);
				}
				
				System.out.println("PASSWORD CHANGED");
			}
		});
		pnlAccount.add(btnChangePassword);
		
		JButton btnBack = new JButton("Back");
		btnBack.setBounds(651, 541, 97, 25);
		btnBack.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
//				windowsApp.getFrame().setContentPane(new Overview(windowsApp).getPanel());
			}
		});
		pnlAccount.add(btnBack);
		
		JLabel lblFirstName = new JLabel("First Name");
		lblFirstName.setBounds(50, 158, 90, 16);
		pnlAccount.add(lblFirstName);
		
		JLabel lblLastName = new JLabel("Last Name");
		lblLastName.setBounds(50, 191, 75, 16);
		pnlAccount.add(lblLastName);
		
		txtFirstName = new JTextField();
		txtFirstName.setBounds(180, 155, 325, 22);
		pnlAccount.add(txtFirstName);
		txtFirstName.setColumns(10);
		
		txtLastName = new JTextField();
		txtLastName.setBounds(180, 190, 325, 22);
		pnlAccount.add(txtLastName);
		txtLastName.setColumns(10);
		
		JButton btnChangeFirstName = new JButton("Change First Name");
		btnChangeFirstName.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				//do stuff
			}
		});
		btnChangeFirstName.setBounds(530, 154, 150, 25);
		pnlAccount.add(btnChangeFirstName);
		
		JButton btnChangeLastName = new JButton("Change Last Name");
		btnChangeLastName.setBounds(530, 187, 150, 25);
		btnChangeLastName.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				//do stuff
			}
		});
		pnlAccount.add(btnChangeLastName);
	}
}
